package org.example.Servlet.PersonServlet;

import org.example.Dao.PersonDao;
import org.example.Dao.TopicDao;
import org.example.entity.Person;
import org.example.entity.Topic;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.List;

@WebServlet("/admin/index")
public class AdminIndexServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        HttpSession session = req.getSession();
        PersonDao personDao = new PersonDao();
        TopicDao topicDao = new TopicDao();
        // 主备好普通用户信息
        List<Person> personList = null;
        try {
            personList = personDao.getNormalPersonList();
            System.out.println("personList ==> " + personList.toString());
            session.setAttribute("personList", personList);
            // 准备好主题集合
            List<Topic> topicList = topicDao.getTopicList();
            System.out.println("topicList ==> " + topicList.toString());
            session.setAttribute("topicList", topicList);

        } catch (Exception e) {
            System.out.println("to admin index error ==> " + e.getMessage());
        }
        resp.sendRedirect(req.getContextPath() + "/views/admin/index.jsp");

    }
}
